<template>
    <div></div>
</template>

<script>
    import Xurl from "../x/xurl";
    import Vue from 'vue'

    export default {
        data() {
            return {
                sessionKey: "currentBrowseKey",
                currentBrowseKey: window.sessionStorage.getItem(Vue.prototype.CURRENTBROWSEKEY)
            }
        },
        mounted() {
            this.initBrowse();
            // 60秒执行一次
            setInterval(this.updateBrowseTime, 60 * 1000);
        },
        methods: {
            // 更新浏览记录访问时间
            updateBrowseTime() {
                let key = window.sessionStorage.getItem(this.sessionKey);
                if (typeof key != "string" || key.trim().length == 0) {
                    return;
                }
                if (typeof this.currentBrowseKey == "string" && this.currentBrowseKey.trim().length != 0) {
                    let url = this.NW_API_vue + "/consumers/browses?browseToken=" + key;
                    Xurl.put(url)
                }
            },

            // 判断页面加载方式，初始化浏览数据
            initBrowse() {
                if (window.performance.navigation.type != window.performance.navigation.TYPE_RELOAD
                        && window.performance.navigation.type != window.performance.navigation.TYPE_BACK_FORWARD) {
                    // 新加载的页面：保存浏览令牌到本地，发送浏览请求
                    window.sessionStorage.setItem(this.sessionKey, this.currentBrowseKey);
                    this.updateBrowseTime();
                }
            }
        }
    }
</script>

<style scoped>

</style>
